package edu.ptit.jad.model;

import java.awt.image.TileObserver;

import edu.ptit.jad.exception.AdException;

/**
 * Document is reperent for an artical, a new or any documents
 * 
 * @author PhuongDo
 * 
 */
public class Document extends Content {

	private int id;
	private String title;
	private String summary;
	private String content;

	

	public Document(int id, String title, String summary, String content) {

		super(id, title + " " + summary + " " + content);
		this.id = id;
		this.title = title;
		this.summary = summary;
		this.content = content;
	}

	/**
	 * 
	 * @param row
	 * @throws AdException
	 */
	public Document(String row) throws AdException {

		this.convertToDocument(row);
	}

	public Document() {

	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getSummary() {
		return summary;
	}

	public void setSummary(String summary) {
		this.summary = summary;
	}

	@Override
	public String toString() {

		return String.format("%d::::%s::::%s::::%s", id, title, summary,
				content);
	}

	/**
	 * 
	 * @param String
	 *            ad row format for document split by ::
	 * @throws AdException
	 */

	private void convertToDocument(String row) throws AdException {

		try {

			// System.err.println(row);
			String[] splits = row.split(": : : :");

			id = Integer.parseInt(splits[0].trim());
			title = splits[2].trim();
			summary = splits[3].trim();
			content = splits[4].trim();

		} catch (Exception exception) {

			// exception.printStackTrace();
			System.err.println("Convert to object error! at " + row);

			// throw new AdException("Convert to object error! at " + row);

		}

	}

}
